  import axios from 'axios'
import {
  API
} from 'fac/constant.js'
export default {
  namespaced: true,
  state: {
    //接口请求返回，后台可配置
    filter: {
      dep: [{
          id: '0',
          text: '不限'
        },
        {
          id: '1',
          text: '公共'
        },
        {
          id: '2',
          text: '客服'
        },
        {
          id: '3',
          text: '产品'
        },
        {
          id: '4',
          text: '运营'
        },
        {
          id: '5',
          text: '推广'
        }
      ],
      cate: [{
          id: '0',
          text: '不限'
        }, {
          id: '1',
          text: '规章制度'
        },
        {
          id: '2',
          text: '文档模板'
        },
        {
          id: '3',
          text: '工作培训'
        }, {
          id: '4',
          text: '存档文件'
        }
      ]
    },

    category: {
      'newest-upload': '最新上传',
      'hot-download': '热门下载'
    },
    sections: [{
        category: 'newest-upload',
        moreLink: 'newest-upload'
      },
      {
        category: 'hot-download',
        moreLink: 'hot-download'
      }
    ],
    query: {
      dep: '0',
      cate: '0'
    }
  },
  getters: {
    sections(state, getters, rootState, rootGetters) {

      let sections = state.sections.map((item) => {
        item.title = state.category[item.category]
        item.route = {
          path: item.moreLink,
          query: {
            ...state.query,
            ...{
              search: rootState.search.search
            }
          }
        };
        return item;
      });
      return sections;
    }
  },
  mutations: {
    //设置过滤器
    setFilters(state, {
      dep,
      cate
    }) {
      state.query.dep = dep;
      state.query.cate = cate;
    },

    //改变过滤器
    switchFilter(state, {
      fType,
      fCur
    }) {
      state.query[fType] = fCur;
    }
  },
  actions: {

    //获取过滤器中的部分列表
    getLevelOneFilter(id) {
      axios({
        url: API.GetDeptList,
        params: {
          id
        }
      }).then((data) => {

      })
    }
  }
}
